package com.hdcircles.autoform.ui.label.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hdcircles.autoform.R;
import com.hdcircles.autoform.model.bean.FormBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hdcircles on 2016/11/22.
 */

public class MouldAdapter extends RecyclerView.Adapter<MouldAdapter.ViewHolder>{

    private List<FormBean> formBeanList;

    private onItemClickListener itemClickListener;

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_form_list,parent,false));
    }

    public void setFormBeanList(List<FormBean> formBeanList) {
        this.formBeanList = formBeanList;
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final FormBean form=formBeanList.get(position);
        holder.tvTitle.setText(form.getFormName());
        holder.tvTime.setVisibility(View.GONE);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemClickListener.onItemClick(form);
            }
        });
    }

    @Override
    public int getItemCount() {
        return null==formBeanList?0:formBeanList.size();
    }

    public void setItemClickListener(onItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    public interface onItemClickListener{

        void onItemClick(FormBean formBean);
    }

    static class ViewHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.tv_question_title)
        TextView tvTitle;
        @BindView(R.id.tv_time)
        TextView tvTime;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
